package com.team.six.bluecatshop.controller;

import com.team.six.bluecatshop.domain.SeachIndentResponse;
import com.team.six.bluecatshop.service.IndentService;
import com.team.six.bluecatshop.service.ProductService;
import com.team.six.bluecatshop.service.ProductTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;


@RequestMapping("/adminIndent")
@Controller
public class AdminIndentController {
    @Autowired
    ProductService productService;
    @Autowired
    ProductTypeService productTypeService;
    @Autowired
    IndentService indentService;

    /**
     * 跳转至订单展示页面
     */
    @GetMapping("/indentList")
    public String productGetList(){
        return "administration/indent_list";
    }

    /**
     * 处理商品展示请求
     * @return
     */
    @GetMapping("/api/indentList")
    @ResponseBody
    public SeachIndentResponse seachIndentResponse(Integer pageNum, Integer pageSize){
        return indentService.findIndentAll(pageNum,pageSize);
    }



    /**
     * 处理删除请求
     */
    @GetMapping("/deleteIndent")
    public String deleteProduct(String indentId){
        indentService.remove(indentId);
        return "redirect:/adminIndent/indentList";
    }


    /**
     * 批量删除
     */
    @PostMapping("/batchDelete")
    @ResponseBody
    public String batchDelete(String indents){
        String[] split = indents.split(",");
        for (int i=0;i<split.length;i++){
            System.out.println(split[i]);
            indentService.remove(split[i]);
        }
//        System.out.println(products);
        return "删除成功";
    }
}
